package libs
{
	import com.adobe.serialization.json.JSON;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.ResultEvent;

	public  class ToolKit
	{
		
		public var arr:Array = new Array();
		
		public function ToolKit()
		{
			
			
		}
		
		/**
		 * 轉換JSON格式為ComBox組件下拉列表可用的數據格式
		 * 
		 * 
		 * */
		public function JSON2ComboxData(jsonData:Object,labelName:String,dataName:String):ArrayCollection
		{
			
			var arr:Array = JSON.decode(String(jsonData)) as Array;
			
			var re:Array = new Array();
			
			for(var i:int=0;i<arr.length;i++)
			{
				
				re.push({"label":arr[i][labelName],"data":arr[i][dataName]});
				
			}
			
			return new ArrayCollection(re);
		}
		
		/**
		 * 轉換JSON格式到ArrayCollection
		 * */
		public function JSON2ArrayCollection(jsonData:Object):ArrayCollection
		{
			var array:ArrayCollection =	 new ArrayCollection(JSON.decode(String(jsonData)) as Array);
			
			
			return array;
			
		}
		
	}
}